package krow.dev.gunpobus;

import java.util.List;
import java.util.Map;

import krow.dev.gunpobus.control.database.DataController;
import krow.dev.gunpobus.control.http.BitmapCache;
import krow.dev.gunpobus.model.RouteItem;
import krow.dev.gunpobus.model.StationItem;
import android.app.Application;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;

/**
 * GlobalStore
 * 
 * @author syuan
 * @since 2013. 10. 4.
 */
public class GlobalStore extends Application {

	private static GlobalStore mInstance;

	private RequestQueue mRequestQueue;

	private ImageLoader mImageLoader;

	private DataController mDataController;

	private Map<String, RouteItem> mRouteItemMap;

	private Map<String, StationItem> mStationItemMap;

	private List<RouteItem> mRouteItemList;

	private List<StationItem> mStationItemList;

	@Override
	public void onCreate() {
		super.onCreate();
		mInstance = this;

		mRequestQueue = Volley.newRequestQueue(getApplicationContext());
		mImageLoader = new ImageLoader(mRequestQueue, new BitmapCache());
		mRequestQueue.start();

		mDataController = new DataController(getApplicationContext());
	}

	@Override
	public void onTerminate() {
		mRequestQueue.stop();
		super.onTerminate();
	}

	/**
	 * @Method getInstance
	 * @author syuan
	 * @since 2013. 10. 4.
	 * @return GlobalStore
	 */
	public static GlobalStore getInstance() {

		return mInstance;
	}

	/**
	 * @Method getRequestQueue
	 * @author syuan
	 * @since 2013. 10. 4.
	 * @return RequestQueue
	 */
	public RequestQueue getRequestQueue() {

		return mRequestQueue;
	}

	/**
	 * @Method getImageLoader
	 * @author syuan
	 * @since 2013. 10. 4.
	 * @return ImageLoader
	 */
	public ImageLoader getImageLoader() {

		return mImageLoader;
	}

	public boolean isAvailable() {

		return (mRouteItemMap != null);
	}

	public DataController getDataController() {

		return mDataController;
	}

	public Map<String, RouteItem> getRouteItemMap() {
		return mRouteItemMap;
	}

	public void setRouteItemMap(Map<String, RouteItem> routeItemMap) {
		mRouteItemMap = routeItemMap;
	}

	public List<RouteItem> getRouteItemList() {
		return mRouteItemList;
	}

	public void setRouteItemList(List<RouteItem> routeItemList) {
		mRouteItemList = routeItemList;
	}

	public Map<String, StationItem> getStationItemMap() {
		return mStationItemMap;
	}

	public void setStationItemMap(Map<String, StationItem> stationMap) {
		mStationItemMap = stationMap;
	}

	public List<StationItem> getStationItemList() {
		return mStationItemList;
	}

	public void setStationItemList(List<StationItem> stationItemList) {
		mStationItemList = stationItemList;
	}
}
